package leetcode;

import java.util.ArrayList;
import java.util.List;

public class LC39 {
    public static void main(String[] args) {

    }
    public int diameterOfBinaryTree(TreeNode root) {
        List<Integer> ans = new ArrayList<>();
        max(root,ans);
        System.out.println(ans);
        int max = 0;
        for (Integer an : ans) {
            max = Math.max(an,max);
        }
        return max;
    }
    public int max(TreeNode root, List<Integer> ans){
        if(root == null) return 0;
        int left = max(root.left,ans);
        int right = max(root.right,ans);
        ans.add(left + right);
        return Math.max(left,right) + 1;
    }
}
